﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Imagin.Controls.Common"
    xmlns:System="clr-namespace:System;assembly=mscorlib">
    
    <System:Double x:Key="DisabledOpacity">0.4</System:Double>

    <Style x:Key="Style.RadioButton" TargetType="{x:Type RadioButton}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderBrush" Value="{Binding BorderBrush, RelativeSource={RelativeSource AncestorType={x:Type local:RadioGroup}}}"/>
        <Setter Property="BorderThickness" Value="0,0,1,0"/>
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="Foreground" Value="{DynamicResource Brush.Text}"/>
        <Setter Property="Margin" Value="0,0,-1,0"/>
        <Setter Property="Padding" Value="{Binding Padding, RelativeSource={RelativeSource AncestorType={x:Type local:RadioGroup}}}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RadioButton}">
                    <BulletDecorator>
                        <Border 
                            Background="{TemplateBinding Background}" 
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Padding="{TemplateBinding Padding}">
                            <TextBlock 
                                FontFamily="{TemplateBinding FontFamily}"
                                FontSize="{TemplateBinding FontSize}"
                                FontStretch="{TemplateBinding FontStretch}"
                                FontWeight="{TemplateBinding FontWeight}"
                                Foreground="{TemplateBinding Foreground}">
                                <InlineUIContainer><ContentPresenter /></InlineUIContainer>
                            </TextBlock>
                        </Border>
                    </BulletDecorator>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsChecked" Value="False"/>
                    <Condition Property="IsMouseOver" Value="True"/>
                </MultiTrigger.Conditions>
                <Setter Property="Background" Value="{DynamicResource Brush.RadioGroup.MouseOver.Background}" />
                <Setter Property="Cursor" Value="Hand" />
                <Setter Property="Foreground" Value="{DynamicResource Brush.RadioGroup.MouseOver.Foreground}" />
            </MultiTrigger>
            <Trigger Property="IsChecked" Value="True">
                <Setter Property="Background" Value="{DynamicResource Brush.RadioGroup.Checked.Background}" />
                <Setter Property="Cursor" Value="Arrow" />
                <Setter Property="Foreground" Value="{DynamicResource Brush.RadioGroup.Checked.Foreground}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Opacity" Value="{StaticResource DisabledOpacity}" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style TargetType="local:RadioGroup">
        <Setter Property="ItemContainerStyle" Value="{StaticResource Style.RadioButton}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:RadioGroup}">
                    <local:ClippedBorder 
                        Background="{TemplateBinding Background}" 
                        BorderBrush="{TemplateBinding BorderBrush}"  
                        BorderThickness="{TemplateBinding BorderThickness}" 
                        CornerRadius="{TemplateBinding CornerRadius}">
                        <StackPanel  
                            IsItemsHost="True" 
                            Orientation="Horizontal"/>
                    </local:ClippedBorder>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>